class Solution {  //环，循环往复——》快慢指针
public:
    int BitSum(int n)  //计算数的每个位置的平方和
    {
        int total = 0;
        while(n)  //%、/搭配可以依次从后往前得到每一位数
        {
            total += pow(n%10, 2);  //提取个位
            n /= 10;  //干掉个位
        }
        return total;
    }
 
    bool isHappy(int n) {  
        int slow = n, fast = BitSum(n);
        while(slow != fast)
        {  //快慢指针，每次让快指针走一步，每次让快指针走两步
            slow = BitSum(slow); 
            fast = BitSum(BitSum(fast));
        }
        return slow == 1;
    }
};